package com.ruoyi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TRealm;
import com.ruoyi.system.service.ITRealmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 域名Controller
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/system/realm")
public class TRealmController extends BaseController
{
    @Autowired
    private ITRealmService tRealmService;

    /**
     * 查询域名列表
     */
    @PreAuthorize("@ss.hasPermi('system:realm:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRealm tRealm)
    {
        startPage();
        List<TRealm> list = tRealmService.selectTRealmList(tRealm);
        return getDataTable(list);
    }

    /**
     * 导出域名列表
     */
    @PreAuthorize("@ss.hasPermi('system:realm:export')")
    @Log(title = "域名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRealm tRealm)
    {
        List<TRealm> list = tRealmService.selectTRealmList(tRealm);
        ExcelUtil<TRealm> util = new ExcelUtil<TRealm>(TRealm.class);
        util.exportExcel(response, list, "域名数据");
    }

    /**
     * 获取域名详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:realm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tRealmService.selectTRealmById(id));
    }

    /**
     * 新增域名
     */
    @PreAuthorize("@ss.hasPermi('system:realm:add')")
    @Log(title = "域名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRealm tRealm)
    {
        return toAjax(tRealmService.insertTRealm(tRealm));
    }

    /**
     * 修改域名
     */
    @PreAuthorize("@ss.hasPermi('system:realm:edit')")
    @Log(title = "域名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TRealm tRealm)
    {
        return toAjax(tRealmService.updateTRealm(tRealm));
    }

    /**
     * 删除域名
     */
    @PreAuthorize("@ss.hasPermi('system:realm:remove')")
    @Log(title = "域名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tRealmService.deleteTRealmByIds(ids));
    }
}
